<?php
/**
 *
 *
 */
class TicketController extends AppController
{
    public $name       = "Ticket";
    public $uses       = array('Ticket', 'TicketExtra', 'TicketDetail', 'Extra', 'User', 'Status', 'SmtpSetting');
    public $components = array('MyEmail');

    public $paginate;



    //----------------------------------------------------------------------------------
    // begin: public page
    //----------------------------------------------------------------------------------
    public function start()
    {
        $this->theme  = "open";
        $this->layout = "startpage";

        parent::set('page_title', 'Helpdesk Assistance');
        parent::set('sidebar', 0);
    }

    public function checkstatus()
    {
        $this->theme  = "open";
        $this->layout = "open";

        $ticketId = $this->data['status']['ticketno'];
        $status = null;

        // get ticket status
        if ($ticketId) {

            $parent = $this->Ticket->get_ticket('first', array('ticketCode' => $ticketId), array('ticketId', 'status'));
            if ($parent) {
                $status['ticketId'] = $parent['Ticket']['ticketId'];
                $status['status'] = $parent['Ticket']['status'];

                $cfields = array('ticketDetailId', 'action_taken', 'recommendation', 'date_taken_action', 'date_updated');
                $status['remarks'] = $this->TicketDetail->get_detail('all', array('ticketId' => $status['ticketId']), $cfields, array('date_updated' => 'desc'));
            }

        }

        parent::set('page_title', 'Check Status');
        parent::set('sidebar', 0);
        parent::set('status', $status);
        parent::set('ticket_code', $ticketId);
        parent::set('visibility', (count($status['remarks']) > 0) ? "visible" : "hidden");
    }

    public function opencreate()
    {
        $this->theme  = "open";
        $this->layout = "open";

        if ($this->data['create']['button'] == 'Create') {
            $view = 'review';
            $this->data['create']['department_value'] = $this->Extra->get_extras_value($this->data['create']['department']);
            $this->data['create']['priority_value'] = $this->Extra->get_extras_value($this->data['create']['priority']);
            self::set('summary', $this->data);
        } else if ($this->data['create']['button'] == 'Back') {
            $view = "";
            $details['create']['your_name'] = isset($this->data['create']['your_name'])?$this->data['create']['your_name']:null;
            $details['create']['email_address'] = isset($this->data['create']['email_address'])?$this->data['create']['email_address']:null;
            $details['create']['department'] = isset($this->data['create']['department'])?$this->data['create']['department']:null;
            $details['create']['priority'] = isset($this->data['create']['priority'])?$this->data['create']['priority']:null;
            $details['create']['subject'] = isset($this->data['create']['subject'])?$this->data['create']['subject']:null;
            $details['create']['summary'] = isset($this->data['create']['summary'])?$this->data['create']['summary']:null;
        } else {
            // save ticket information to db
            $result = self::create();
            $view = "";
            if ($result['msg']) {
                $recipient = array();
                $mailing_list = $this->Extra->get_extras_data("MAILING_LIST");
                $notify[0][] = array("email" => $result['owner_email'], "template" => "notify_new_ticket_b");

                $notify[1][] = array("email" => $mailing_list['Extra']['value'], "template" => "notify_new_ticket_a");
                $data['ticket_id'] = $result['ticket_id'];

                if (!self::send_email($notify, "New Ticket", $data)) {
                    $msg = "Error sending ticket notification";
                } else {
                    self::redirect('/ticket/confirmation/'.$result['ticket_id']);
                }
            }
        }

        self::set('departments', $this->Extra->myGenerateList("etype='DEPARTMENT'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('priorities', $this->Extra->myGenerateList("etype='PRIORITY'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('msg', isset($msg)?$msg:null);
        self::set('page_title', 'Send a Report');
        self::set('view', $view);
        self::set('details', isset($details)?$details:null);
    }

    public function ticketaction($tId)
    {
        $this->theme = "open";
        $this->layout = "open";

        if ($this->data['feedback']['remarks']) {
            $update['remarks'] = $this->data['feedback']['remarks'];
            $update['date_updated'] = date('Y-m-d H:i:s');
            if ($this->data['feedback']['confirm'] == 'yes') {
                $ticketUpdate['status'] = 'Closed';
                $update['is_public'] = 0;
                $update['date_confirmed'] = date('Y-m-d H:i:s');
            } else {
                $ticketUpdate['status'] = 'In Progress';
            }

            $res_td = $this->TicketDetail->_save($update, $this->data['feedback']['ticketdetailId']);
            if ($res_td) {
                $res_t = $this->Ticket->_save($ticketUpdate, $tId);
                $msg = 'Thank you';
            } else {
                $msg = 'Error posting your response';
            }
        }

        $detail = $this->TicketDetail->get_detail('first', array('ticketDetailId' => $tId, 'is_public' => 1), array());
        if ($detail) {
            $data['ticketDetailId'] = $detail['TicketDetail']['ticketDetailId'];
            $data['ticketId'] = $detail['TicketDetail']['ticketId'];
            $data['date_taken_action'] = $detail['TicketDetail']['date_taken_action'];
            $data['action_taken'] = $detail['TicketDetail']['action_taken'];
            $data['recommendation'] = $detail['TicketDetail']['recommendation'];
        } else {
            $data = null;
        }

        self::set('page_title', 'Confirm Ticket Action');
        self::set('detail', $data);
        self::set('msg', isset($msg)?$msg:null);
    }

    public function confirmation($ticketid)
    {
        $this->theme = "open";
        $this->layout = "open";
        self::set('ticketid', $ticketid);
        self::set('page_title', 'Ticket Confirmation');
    }
    //----------------------------------------------------------------------------------
    // end: public page
    //----------------------------------------------------------------------------------



    /**
     *  @param $tId int
     *  @return void
     */
    public function createticket($tId = null)
    {
        $this->Authenticate->checkMyLogin(1);
        $this->theme = "admin";

        // query ticket details based on the ticket id
        // passed in the method
        if ($tId) {
            $condition = array('ticketId' => $tId, 'deleted' => 0);
            $ticket_details = $this->Ticket->get_ticket('first', $condition, array());
            $ticket_extra_details = $this->TicketExtra->get_ticket_extra(array('ticketId' => $tId), array());
        }

        switch($this->data['flag']){
            case "back":
                self::redirect('/ticket/ticketmgnt');
                break;

            case "Create" || "Update":
                if ($this->data['create']) {
                    // supply owner and owner's email address if ticket creator is
                    // an administrator or tech support engr.
                    // if sessios is invalid redirect to login screen.
                    if ($this->Session->check('usersess')) {
                        $user_info = $this->Session->read('usersess');
                        $this->data['create']['your_name'] = $user_info['User']['uname'];
                        $this->data['create']['email_address'] = $user_info['User']['email'];
                    } else {
                        self::flash('Invalid session! Please login.', '/user/login', 2);
                    }

                    // save ticket information to db
                    $result = self::create($tId);
                    if ($result['msg']) {
                        $msg = $result['msg'];
                    } else {
                        $msg = "Error creating ticket";
                    }
                }
                break;
        } // switch


        self::set('log_types', $this->Extra->myGenerateList("etype='LOG TYPE'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('categories', $this->Extra->myGenerateList("etype='CATEGORY'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('items', $this->Extra->myGenerateList("etype='ITEM'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('infrastructures', $this->Extra->myGenerateList("etype='INFRASTRUCTURE'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('departments', $this->Extra->myGenerateList("etype='DEPARTMENT'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('locations', $this->Extra->myGenerateList("etype='LOCATION'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('charges', $this->Extra->myGenerateList("etype='CHARGE'", "value ASC", null, "{n}.Extra.extrasId", "{n}.Extra.value"));
        self::set('ticket', isset($ticket_details)?$ticket_details:null);
        self::set('ticket_extra', isset($ticket_extra_details)?$ticket_extra_details:null);
        self::set('ticketId', ($tId)?$tId:null);
        self::set('msg', isset($msg)?$msg:null);
    }

    public function ticketmgnt($extras = "")
    {
        $this->Authenticate->checkMyLogin();
        $this->theme = "admin";

        // search
        $def_condition = array('deleted' => 0);
        if ($extras) {
            if (!is_numeric($extras)) {
                switch ($extras) {
                    case "open":
                        $status = array('status' => "Open");
                        break;
                    case "inprogress":
                        $status = array('status' => "In Progress");
                        break;
                    case "resolved":
                        $status = array('status LIKE' => "Resolved%");
                        break;
                }

                $conditions = array_merge($status, $def_condition);
            }
        } else {
            if ($this->data['search']) {
                if ($this->data['search']['ticketno']) {
                    $ticketno = array('ticketId like' => $this->data['search']['ticketno']);
                } else {
                    $ticketno = array();
                }

                if ($this->data['search']['subject']) {
                    $subject = array('subject like' => $this->data['search']['subject']);
                } else {
                    $subject = array();
                }

                if ($this->data['search']['status']) {
                    $status = array('status like' => "%".mysql_escape_string($this->data['search']['status']));
                } else {
                    $status = array();
                }

                if ($this->data['search']['date_added'] && $this->data['search']['date_ended']) {
                    $date = array("date_added ? between ?" =>
                                   array($this->data['search']['date_added'], $this->data['search']['date_ended']));
                } else {
                    $date = array();
                }

                if ($this->data['search']['person']) {

                    $pos1 = stripos($this->data['search']['person'], '%');
                    $pos2 = stripos($this->data['search']['person'], '_');
                    if ($pos1 === false && $pos2 === false) {
                        $owner = array('owner' => $this->data['search']['person']);
                    } else {
                        $owner = array('owner LIKE ' => $this->data['search']['person']);
                    }

                } else {
                    $owner = array();
                }

                // generate search filters based on the selected
                // search field criteria
                $merge = array_merge($ticketno, $subject, $status, $date, $owner, $def_condition);
                if (count($merge) > 1) {
                    $conditions = array('AND' => $merge);
                } else {
                    $conditions = $merge;
                }
            } else {
                $conditions = array_merge(array('status' => "Open"), $def_condition);
            }
        }

        // action
        if ($this->data['flag']) {
            switch ($this->data['flag']) {
                case "response":
                    self::redirect('/ticket/ticketresponse/'.$this->data['ticketId']);
                    break;

                case "take":
                    $this->Authenticate->checkMyLogin(3);

                    if ($this->data['request']) {
                        $data['ticketId'] = $this->data['ticketId'];
                        $data['action_by'] = $this->Authenticate->getUserLoggedIn();
                        $data['date_taken_action'] = date('Y-m-d H:i:s');

                        $tdId = $this->TicketDetail->_save($data);
                        if (!is_numeric($tdId)) {
                            $msg = implode($tdId);
                        } else {
                            $ret = $this->Ticket->_save(array('status' => 'In Progress'), $this->data['ticketId']);
                            $msg = "You have successfully assigned ticket# ".$this->data['ticketId']." to yourself";
                        }
                    }
                    break;

                case "assignto":
                    self::redirect('/ticket/assignto/'.$this->data['ticketId']);
                    break;

                case "recall":
                    foreach($this->data['row']['id'] as $id){
                        $retId = $this->Ticket->_save(array('deleted' => 0), $id);
                        if (!is_numeric($retId)) {
                            $msg = implode(", ", $retId);
                            break;
                        }
                    }
                    break;

                case "delete":
                    $this->Authenticate->checkMyLogin(2);
                    foreach($this->data['row']['id'] as $id){
                        $retId = $this->Ticket->_save(array('deleted' => 1), $id);
                        if (!is_numeric($retId)) {
                            $msg = implode(", ", $retId);
                            break;
                        }
                    }
                    break;

                case "add":
                    self::redirect('/ticket/createticket');
                    break;
            }
        }

        $status = $this->Status->MyGenerateList("active=1", null, null, "{n}.Status.code", "{n}.Status.code");
        //general tickets
        $limit = isset($this->data['limit'])?$this->data['limit']:20;
        $this->paginate['conditions'][] = $conditions;
        $this->paginate['limit'] = $limit;
        $this->paginate['order'] = array('date_added' => 'DESC');
        $data = $this->paginate('Ticket');

        //own ticket
        $user_info = $this->Session->read('usersess');
        $td = $this->TicketDetail->get_detail(
            'all',
            array('action_by' => $user_info['User']['userId']),
            array('ticketDetailId', 'ticketId', 'date_updated'),
            array('date_updated DESC'),
            array('ticketId')
        );
        if ($td) {
            foreach($td as $k => $v){
                $t = $this->Ticket->get_ticket('all', array('ticketid' => $v['TicketDetail']['ticketId']), array('subject', 'status', 'date_added'));
                if ($t) {
                    $tdetails[$k]['ticketDetailId'] = $v['TicketDetail']['ticketDetailId'];
                    $tdetails[$k]['ticketId'] = $v['TicketDetail']['ticketId'];
                    $tdetails[$k]['subject'] = $t[0]['Ticket']['subject'];
                    $tdetails[$k]['status'] = $t[0]['Ticket']['status'];
                    $tdetails[$k]['date_added'] = $t[0]['Ticket']['date_added'];
                    $tdetails[$k]['date_updated'] = $v['TicketDetail']['date_updated'];
                } else {
                    $tdetails = array();
                }
            }
        } else {
            $tdetails = array($ticket_ref);
        }

        // get deleted tickets
        $bypass = $this->Authenticate->checkMyLogin(28, true);
        $deleted = null;
        if ($bypass) {
            $raw_deleted = $this->Ticket->get_ticket('all', array('deleted' => 1), array('*'), 100);
            foreach ($raw_deleted as $k => $rd) {
                $deleted[$k]['ticketId'] = $rd['Ticket']['ticketId'];
                $deleted[$k]['subject'] = $rd['Ticket']['subject'];
                $deleted[$k]['priority'] = $rd['Ticket']['priority'];
                $deleted[$k]['date_added'] = $rd['Ticket']['date_added'];
                $deleted[$k]['date_updated'] = $rd['Ticket']['date_updated'];
            }
        }

        $stats = $this->Ticket->get_stats();
        $critical = $this->Ticket->get_critical();
        $persons = array('...' => 'Select here...', 'owner' => 'Owner', 'tech' => 'Tech. Engineers');

        self::set('limit', $limit);
        self::set('data', $data);
        self::set('mine', $tdetails);
        self::set('status', $status);
        self::set('deleted', $deleted);
        self::set('dcount', count($deleted));
        self::set('count', count($data));
        self::set('critical', $critical);
        self::set('bypass', $bypass);
        self::set('ticket_unique', isset($unique)?$unique:null);
        self::set('stats', ($stats)?$stats:null);
        self::set('persons', $persons);
        self::set('msg', isset($msg)?$msg:null);
    }

    public function ticketresponse($tId)
    {
        $this->Authenticate->checkMyLogin(5);
        $this->theme = "admin";

        $tdId = $this->TicketDetail->get_id($tId);
        $tdetailId = ($this->data['action']['ticketDetailId'])?$this->data['action']['ticketDetailId']:$tdId[0]['ticket_details']['ticketDetailId'];
        if ($this->data['action']) {
            $data['ticketId'] = $tId;
            $data['action_taken'] = $this->data['action']['action_taken'];
            $data['recommendation'] = $this->data['action']['recommendation'];
            $data['action_by'] = $this->Authenticate->getUserLoggedIn();
            $data['date_taken_action'] = date('Y-m-d H:i:s');
            $data['is_public'] = 1;
            if (!empty($tdId[0]['action_taken']) && !empty($tdId[0]['recommendation'])) {
                $ret = $this->TicketDetail->_save($data, $tdId[0]['ticket_details']['ticketDetailId']);
            } else {
                $ret = $this->TicketDetail->_save($data);
            }

            // sent link to owner to validate ticket
            $ticket = $this->Ticket->get_ticket('first', array('ticketId' => $tdetailId), array('ticketId', 'owner_email'));
            if ($ticket) {
                if ($this->data['button'] == 'Update') {
                    $status = 'In Progress';
                } else {
                    $status = "Resolved / Pending Confirmation";
                }

                $update = $this->Ticket->_save(array('status' => $status), $tId);
                if ($status == "Resolved / Pending Confirmation") {
                    $notify[0][] = array("email" => $ticket['Ticket']['owner_email'], "template" => "verification");
                    //$notify[0][] = array("email" => 'john@127.0.0.1', "template" => "verification");
                    $data['link'] = "http://".$_SERVER['HTTP_HOST']."/ticket/ticketaction/".$ticket['Ticket']['ticketId'];
                    if (!self::send_email($notify, "Ticket Resolution", $data)) {
                        $msg = "Error sending ticket resolution";
                    } else {
                        $msg = 'Your response has been posted';
                    }
                }

            }

            if (!is_numeric($ret)) {
                $msg = implode(", ", $ret);
            } else {
                $msg = "Responce successfully saved";
            }
        }

        $status = $this->Status->MyGenerateList("statusId IN (2, 3) and active=1", null, null, "{n}.Status.code", "{n}.Status.code");
        $ticket = $this->Ticket->get_ticket('first', array('ticketId' => $tId, 'deleted' => 0), array());
        $ticket_details = $this->TicketDetail->get_detail('all', array('ticketId' => $tId), array(), array(), array());
        if ($ticket) {
            $data['subject'] = $ticket['Ticket']['subject'];
            $data['details'] = $ticket['Ticket']['details'];
            $data['cstatus'] = $ticket['Ticket']['status'];
            $data['date_added'] = $ticket['Ticket']['date_added'];
            $data['date_reported'] = $ticket['Ticket']['date_reported'];
            $data['category'] = $this->Extra->get_extras_value($ticket['Ticket']['category']);
            $data['item'] = $this->Extra->get_extras_value($ticket['Ticket']['item']);
            $data['department'] = $this->Extra->get_extras_value($ticket['Ticket']['department']);
            $data['location'] = $this->Extra->get_extras_value($ticket['Ticket']['location']);
            $data['priority'] = $this->Extra->get_extras_value($ticket['Ticket']['priority']);
        }

        self::set('ticketId', $tId);
        self::set('data', $data);
        self::set('ticket_details', $ticket_details);
        self::set('status', $status);
        self::set('ticketDetailId', $tdetailId);
        self::set('msg', isset($msg)?$msg:null);
    }

    public function assignto($tId)
    {
        $this->Authenticate->checkMyLogin(4);
        $this->theme = "admin";
        $success = false;

        // process request
        if ($this->data['assign']['name'] || !empty($this->data['assign']['name'])) {

            $session = $this->Session->read('User');
            $ticket_detail['ticketId'] = $this->data['assign']['ticketId'];
            $ticket_detail['action_by'] = $this->data['assign']['name'];
            $ticket_detail['date_taken_action'] = date('Y-m-d H:i:s');
            $ticket_detail['remarks'] = $this->data['assign']['remarks'];

            // check for duplicate process
            $check = $this->Ticket->get_ticket('first', array('ticketId' => $this->data['assign']['ticketId']), array('status'));
            if ($check['Ticket']['status'] == 'Open') {
                $tdId = $this->TicketDetail->_save($ticket_detail, 0);
                if ($tdId) {
                    $update['status'] = 'In Progress';
                    $this->Ticket->_save($update, $this->data['assign']['ticketId']);
                    $msg = 'You have successfully assigned ticket';
                    $success = true;
                }
            } else {
                $msg = 'This ticket is alread assigned';
            }

        }

        // process toolbar request
        if ($this->data['flag']) {
            switch($this->data['flag']){
                case "back":
                    self::redirect('/ticket/ticketmgnt');
                    break;
            } // switch
        }


        $condition['ticketId'] = $tId;
        $engrs = $this->User->get_user_info('all', array('User.active' => 1), array('User.*'));
        $ticket_details = $this->Ticket->get_ticket('all', $condition, array('*'));
        if ($ticket_details) {
            $data['ticketId'] = $ticket_details[0]['Ticket']['ticketId'];
            $data['subject'] = $ticket_details[0]['Ticket']['subject'];
            $data['details'] = $ticket_details[0]['Ticket']['details'];
            $data['cstatus'] = $ticket_details[0]['Ticket']['status'];
            $data['date_added'] = $ticket_details[0]['Ticket']['date_added'];
            $data['date_reported'] = $ticket_details[0]['Ticket']['date_reported'];
            $data['category'] = $this->Extra->get_extras_value($ticket_details[0]['Ticket']['category']);
            $data['item'] = $this->Extra->get_extras_value($ticket_details[0]['Ticket']['item']);
            $data['department'] = $this->Extra->get_extras_value($ticket_details[0]['Ticket']['department']);
            $data['location'] = $this->Extra->get_extras_value($ticket_details[0]['Ticket']['location']);
        }
        if ($engrs && !$success) {
            foreach($engrs as $v){
                $engr_list[$v['User']['userId']] = $v['User']['lname'].", ".$v['User']['fname'];
            }
        } else {
            $engr_list = array();
        }

        self::set('ticket_details', $data);
        self::set('engrs', $engrs);
        self::set('engr_list', $engr_list);
        self::set('msg', isset($msg)?$msg:null);
    }



    //----------------------------------------------------------------------------------
    // protected methods
    //----------------------------------------------------------------------------------
    protected function create($ticketId = null)
    {
        if ($this->data['create']['your_name'] && $this->data['create']['email_address'] &&
            $this->data['create']['subject'] && $this->data['create']['summary']) {

            $create['owner'] = $this->data['create']['your_name'];
            $create['owner_email'] = $this->data['create']['email_address'];
            $create['location'] = isset($this->data['create']['location'])?$this->data['create']['location']:null;
            $create['logType'] = isset($this->data['create']['log_type'])?$this->data['create']['log_type']:null;
            $create['category'] = isset($this->data['create']['category'])?$this->data['create']['category']:null;
            $create['department'] = isset($this->data['create']['department'])?$this->data['create']['department']:null;
            $create['item'] = isset($this->data['create']['item'])?$this->data['create']['item']:null;
            $create['infrastructure'] = isset($this->data['create']['infrastructure'])?$this->data['create']['infrastructure']:null;
            $create['priority'] = isset($this->data['create']['priority'])?$this->data['create']['priority']:null;
            $create['subject'] = $this->data['create']['subject'];
            $create['details'] = $this->data['create']['summary'];
            if ($ticketId) {
                $create['date_added'] = date('Y-m-d H:i:s');
            }
            $create['status'] = "Open";
            $create['deleted'] = 0;

            // ticket extras
            $create['charge_to'] = isset($this->data['create']['charge_to'])?$this->data['create']['charge_to']:null;
            $textras['actual_cost'] = isset($this->data['create']['actual_cost'])?$this->data['create']['actual_cost']:null;
            $textras['origin'] = $_SERVER['REMOTE_ADDR'];

            $tId = $this->Ticket->_save($create, $ticketId);
            if (is_numeric($tId)) {
                $msg = "Ticket has been created with ticket #{$tId}";

                // generate ticket code and update ticket information
                $ticket_code = self::set_ticket_code();
                $upticket = $this->Ticket->_save(array('ticketCode' => $ticket_code), $tId);

                // save details to ticket extras table
                if ($ticketId) {
                    $uteId = $this->TicketExtra->get_ticket_extra(array('ticketId' => $ticketId), array('ticketExtrasId'));
                } else {
                    $uteId = null;
                }

                $textras['ticketId'] = $tId;
                $teId = $this->TicketExtra->_save($textras, $uteId[0]['TicketExtra']['ticketExtrasId']);
            } else {
                $msg = "Error in creating ticket";
            }

            $result['owner_email'] = $this->data['create']['email_address'];
            $result['ticket_id'] = $tId;
            $result['msg'] = isset($msg)?$msg:null;

            // clear post variables
            unset($this->data['create']);
        }

        return isset($result)?$result:null;
    }

    protected function set_ticket_code()
    {
        $raw = $this->Extra->get_extras_data('TICKETNO_YEAR');
        $last_tId = $this->Extra->get_extras_data('TICKETNO_NO');
        $extras_id = $this->Extra->get_extras_id_by_etype('TICKETNO_NO');
        $yr = $raw['Extra']['value'];
        $static_ticket_id = (($last_tId['Extra']['value'] + 1) * 1);
        $no = str_pad($static_ticket_id, 5, "0", STR_PAD_LEFT);

        // update reference
        $upExtras = $this->Extra->_save(array('value' => $static_ticket_id), $extras_id['Extra']['extrasId']);

        return "{$yr}-{$no}";
    }
}
?>